define(['jquery', 'bootstrap', 'backend', 'table', 'form'], function ($, undefined, Backend, Table, Form) {

    var Controller = {
        index: function () {
            // 初始化表格参数配置
            Table.api.init({
                extend: {
                    index_url: 'on_off_car/index' + location.search,
                    add_url: 'on_off_car/add',
                    //edit_url: 'on_off_car/edit',
                    //del_url: 'on_off_car/del',
                    multi_url: 'on_off_car/multi',
                    import_url: 'on_off_car/import',
                    table: 'on_off_car',
                }
            });

            var table = $("#table");

            // 初始化表格
            table.bootstrapTable({
                url: $.fn.bootstrapTable.defaults.extend.index_url,
                pk: 'id',
                search:false,
                sortName: 'id',
                fixedColumns: true,
                fixedRightNumber: 1,
                columns: [
                    [
                        {checkbox: true},
                        {field: 'information.name', title: __('Information.name'), operate: 'LIKE'},
                        {field: 'class_room', title: __('Information.class_room'), operate: 'LIKE'},
                        {field: 'information.student_number', title: __('Information.student_number'), operate: 'LIKE'},
                        {field: 'information.sex', title: __('Information.sex'),operate: false,searchList: {"1":'男',"2":'女'}, formatter: Table.api.formatter.normal},
                        {field: 'information.grade', title: __('Information.grade'), operate: 'LIKE'},
                        {field: 'car.license_plate', title: __('Car.license_plate'), operate: 'LIKE'},
                        {field: 'IMEI', title: __('Imei'), operate: false},
                        {field: 'RC_NUM', title: __('Rc_num')},
                        {field: 'RC_PRES', title: __('Rc_pres'),operate: false},
                        {field: 'RC_TOTAL', title: __('Rc_total'),operate: false},
                        {field: 'GPS_LNG', title: __('Gps_lng'), operate: 'LIKE',operate: false},
                        {field: 'GPS_LAT', title: __('Gps_lat'), operate: 'LIKE',operate: false},
                        {field: 'TIME', title: __('Time'), operate:'RANGE', addclass:'datetimerange', autocomplete:false, formatter: Table.api.formatter.datetime},
                        {field: 'RC_TYPE', title: __('Rc_type'),operate: false, searchList: {"1":__('Rc_type 1'),"2":__('Rc_type 2')}, formatter: Table.api.formatter.normal},

                        {field: 'operate', title: __('Operate'), table: table, events: Table.api.events.operate,
                            buttons:[
                                {
                                    name: 'detail',
                                    title: '查看位置',
                                    text: '查看位置',
                                    classname: 'btn btn-xs btn-primary btn-dialog',
                                    //icon: 'fa fa-list',
                                    url: "car_position/user?lng={GPS_LNG}&lat={GPS_LAT}",
                                    extend: 'data-area=\'["100%", "100%"]\'',
                                    callback: function (data) {
                                        Layer.alert("接收到回传数据：" + JSON.stringify(data), {title: "回传数据"});
                                    }
                                }
                                /*{
                                    name: 'addtabs',
                                    title: __('新选项卡中打开'),
                                    classname: 'btn btn-xs btn-warning btn-addtabs',
                                    icon: 'fa fa-folder-o',
                                    url: 'car_position/index'
                                }*/
                            ],
                            formatter: Table.api.formatter.operate}
                    ]
                ]
            });

            // 为表格绑定事件
            Table.api.bindevent(table);
        },
        add: function () {
            Controller.api.bindevent();
        },
        edit: function () {
            Controller.api.bindevent();
        },
        api: {
            bindevent: function () {
                Form.api.bindevent($("form[role=form]"));
            }
        }
    };
    return Controller;
});
